import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { getProductSimpleList } from '#/api/erp/product/product';
import { getWarehouseSimpleList } from '#/api/erp/stock/warehouse';

import { $t } from '#/locales';

/** 搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'productId',
      label: $t('views.erp.common.product'),
      component: 'ApiSelect',
      componentProps: {
        placeholder: $t('views.erp.common.productPlaceholder'),
        allowClear: true,
        showSearch: true,
        api: getProductSimpleList,
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      fieldName: 'warehouseId',
      label: $t('views.erp.common.warehouse'),
      component: 'ApiSelect',
      componentProps: {
        placeholder: $t('views.erp.common.warehousePlaceholder'),
        allowClear: true,
        showSearch: true,
        api: getWarehouseSimpleList,
        labelField: 'name',
        valueField: 'id',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'productName',
      title: $t('views.erp.common.product'),
      minWidth: 150,
    },
    {
      field: 'unitName',
      title: $t('views.erp.product.product.unit'),
      minWidth: 100,
    },
    {
      field: 'categoryName',
      title: $t('views.erp.product.product.category'),
      minWidth: 120,
    },
    {
      field: 'count',
      title: $t('views.erp.stock.stock.count'),
      minWidth: 100,
      formatter: 'formatAmount3',
    },
    {
      field: 'warehouseName',
      title: $t('views.erp.common.warehouse'),
      minWidth: 120,
    },
  ];
}
